package com.chen.positioning.user.service;

import com.chen.positioning.feedback.dao.FeedBackMapper;
import com.chen.positioning.feedback.entity.FeedBack;
import com.chen.positioning.user.dao.UserManagementMapper;
import com.chen.positioning.user.entity.UserManagement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户信息 Service
 */
@Service
public class UserManagementService {
	private static final Logger logger = LoggerFactory.getLogger(UserManagementService.class);
	@Autowired
	private UserManagementMapper userManagementMapper;

	@Autowired
	FeedBackMapper feedBackMapper;
	/**
	 * 检测用户名是否可用
	 * @param username
	 * @return
	 */
	public int checkUserName(String username) throws Exception{
		return userManagementMapper.checkUserName(username);
	}

	/**
	 * 注册用户
	 * @param userName
	 * @param password
	 * @return
	 */
	public int addUserMangement(String userName,String password)  throws Exception{
		UserManagement userManagement=new UserManagement();
		userManagement.setUserName(userName);
		userManagement.setPassword(password);
		logger.info("UserManagementService - addUserMangement -userManagement："+userManagement.toString());
		return userManagementMapper.insertUserMangement(userManagement);
	}

	/**
	 * 用户登录
	 * @param userName
	 * @param password
	 * @return
	 */
	public UserManagement userLogin(String userName, String password)  throws Exception{
		UserManagement userManagement=new UserManagement();
		userManagement.setUserName(userName);
		userManagement.setPassword(password);
		logger.info("UserManagementService - userLogin -userManagement："+userManagement.toString());
		return userManagementMapper.userLogin(userManagement);
	}

	/**
	 * 根据用户Id实时查询用户余额是否够
	 * @param userId
	 * @return
	 */
    public UserManagement findAllUserManagementInfo(Integer userId)  throws Exception{
		return userManagementMapper.findAllUserManagementInfo(userId);
    }

	/**
	 * 使用完定位服务后扣除其余额(包月期间不扣除)
	 * @param userId
	 * @return
	 */
	public int updateBalanceByUserId(Integer userId,double blance)  throws Exception {
		return userManagementMapper.updateBalanceByUserId(userId,blance);
	}

	/**
	 * 添加意见反馈
	 * @param feedBack
	 * @return
	 * @throws Exception
	 */
	public int addFeedback(FeedBack feedBack) throws Exception{
		return feedBackMapper.insert(feedBack);
	}
}
